home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10058 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: waldorf.csc.calpoly.edu!galaxy!ostoll
  2. From: ostoll@galaxy.csc.calpoly.edu (Oliver Stoll)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: help: template class, #include myclass.cpp?
  5. Date: 5 Mar 1996 22:09:07 GMT
  6. Organization: Cal Poly Computer Science Dept.
  7. Message-ID: <4hie23$5dd@waldorf.csc.calpoly.edu>
  8. References: <4h763j$2dv@jake.esu.edu>
  9. NNTP-Posting-User: ostoll@galaxy.csc.calpoly.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Jian Pan (pan7064@kutztown.edu) wrote:
  13. : when I declare a template class in a header file myclass.h and define the 
  14. : class (implementation) in a .cpp file myclass.cpp, in my application 
  15. : if I only include the .h file, there will be link error, "unresolved 
  16. : external symbol", if I include the .cpp file, everything is OK.
  17. : If in the .h file is non template class, without including the .cpp file 
  18. : there is no problem. 
  19.  
  20. : What is my problem? I am using VC++ 4.0. Using Borland C++ 4.5, I met the 
  21. : same problem.
  22.  
  23. : Any help will be greatly appreciated.
  24.  
  25. : Jian
  26.  
  27. : pan7064@kutztown.edu
  28.  
  29.  
  30. A template is no real function definition but merely a rule for the compiler
  31. to generate a function or class. Therefore the 'implementation' of the template
  32. functions have to go in the header file, or on instatiating the template
  33. with a class, the compiler does not know how to emit the code you want to
  34. generate.
  35.  
  36.  
  37.  
  38.  
  39. --
  40. -------------------------------------------------------------------------------
  41.                         Oliver "Oyl McDoyle" Stoll
  42.  
  43.  Fachhochschule Karlsruhe                       California Polytechnic State
  44.  stol0012@fh-karlsruhe.de                       University (San Luis Obispo)
  45.  http://www.fh-karlsruhe.de/~stol0012           ostoll@galaxy.csc.calpoly.edu
  46.